import { _decorator, Component, Node, Sprite, SpriteFrame } from 'cc';
import { AdComponent } from '../AdComponent';
import DatasSpace from '../Tool/DatasSpace';
import SkdComm from '../SkdComm';
import { MainGameUI } from '../MainGameUI';
const { ccclass, property } = _decorator;

@ccclass('propTip')
export class propTip extends Component {
    @property(Sprite)
    icon:Sprite=null;
    @property(SpriteFrame)
    iconSpr:SpriteFrame[]=[];
    @property(Node)
    sharebtn:Node=null;

    type:number=0;

    showNum:number=0;
    open(type){
        this.type=type;
        this.icon.spriteFrame=this.iconSpr[type];
        this.node.active=true;
        if(this.showNum<2){
          this.sharebtn.active=true;
        }else{
          this.sharebtn.active=false;
        }
        this.showNum++;
    }
    //广告
    ad(){
      AdComponent.Instance.loadVideoAd(0, (res) => {
        if (res) {
          DatasSpace.Instance.propNumArr[this.type]=1;
          DatasSpace.Instance.setPropNum();
          MainGameUI.inst.initMainGameProp();
        }
        this.close();
      });
    }
    //分享
    share(){
        SkdComm.Instance.shareTo(
            () => {
                DatasSpace.Instance.propNumArr[this.type]=1;
                DatasSpace.Instance.setPropNum();
                // DatasSpace.Instance.ShareCount = 0;
                // EventMgr.emit(EVENT_TYPE.EVENT_UPD_SHARE);
                // MainGameUI.inst.initMainGameProp();
                MainGameUI.inst.initMainGameProp();
                this.close();
            }
        );
    }
    //关闭
    close(){
        this.node.active=false;
    }

   
}


